const roundOffset = val => {
  const res = +val;
  return isNaN(res) ? 0 : Math.round(res / 10) * 10;
};

const getLimitVal = (val, limit, isFormat = true) => {
  let res = 0;
  if (val < 0) {
    res = 0;
  } else if (val > limit) {
    res = limit;
  } else {
    res = val;
  }

  return isFormat ? roundOffset(res) : res;
};
const sizeData = {
  small: {
    width: 64,
    height: 90
  },
  medium: {
    width: 90,
    height: 120
  },
  large: {
    width: 120,
    height: 150
  }
};

const getParentWidth = val => {
  const { direction, child, width, height } = val;
  const size = {
    width,
    height
  };
  if (child && child.length) {
    return size;
  } else {
    if (direction === "vertical") {
      return size;
    } else if (direction === "horizontal") {
      return {
        width: height,
        height: width
      };
    }
  }
};

const getChildWidth = (val, direction) => {
  if (direction === "horizontal") {
    const { width, height } = sizeData[val];
    return {
      width: height,
      height: width
    };
  }
  return sizeData[val];
};

export { roundOffset, getLimitVal, getParentWidth, getChildWidth };
